/*
A(void)
A(void)
A(void)
~A()
~A()
~A()
exception2.cpp: 32:file open failed

 */
#include <iostream>
#include <cstdio>
#include <csetjmp>
using namespace std;
class A{
	public:
		A(void){
			cout << "A(void)" << endl;
		}
		~A(){
			cout << "~A()" << endl;
		}
};
class FileErr{
	private:
		string filename;
		int line;
	public:
		FileErr(const string &name, int num){
			filename = name;
			line = num;
		}
		void print(void) const{
			cout << filename << ": "<< line << ":" << "file open failed" << endl;
		}
};
int func3(){
	A c;

	FILE *fp = fopen("./a.txt", "r");
	if(fp  == NULL){
		throw FileErr(__FILE__, __LINE__);
		//throw -1;   
	}
	cout << "open a.txt successed" << endl;
	fclose(fp);
	return 0;
}
int func2(){
	A b;
	func3();
	return 0;
}
int func1(void){
	A a;
	func2();
	return 0;
}
int main(void){
	try{
		func1();
	}
	catch(int err){
		if(err == -1){
			cout << "handle file open failed" << endl;
			return -1;
		}
	}
	catch(const FileErr& e){
		e.print();
		return -1;
	}
	return 0;
}

